package com.ym.pms.controller;

import com.ym.pms.model.Notice;
import com.ym.pms.service.HomeNoticeService;
import com.ym.pms.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/notice")
@Api(tags = "主页通知信息接口")
public class HomeNoticeController {
    @Autowired
    HomeNoticeService service;

    @GetMapping("/getAllNotice")
    @ApiOperation(value = "获得所有的主页通知信息")
    public JSONResult getAllNotice(){
        Map<String, List<Map<String, String>>> allNotice = service.getAllNotice();
        return JSONResult.ok(allNotice);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加一条通知信息")
    public JSONResult add(Notice notice){
        service.add(notice);
        return JSONResult.ok();
    }
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除一条通知信息")
    @ApiImplicitParam(name = "id", value = "通知主键", required = true, dataType = "int")
    public JSONResult delete(@RequestParam("id")Integer id){
        service.delete(id);
        return JSONResult.ok();
    }
    @PostMapping("/update")
    @ApiOperation(value = "更新一条通知信息")
    public JSONResult update(Notice notice){
        service.update(notice);
        return JSONResult.ok();
    }
}
